# TODO: Add comment
# 
# Author: Forever
###############################################################################
library(hydroGOF)
library(clusterSim)



inputPath = "C:/Users/Forever/Desktop/correl"
inputFile = "npp_aronet"
listFile = list.files(path = inputPath,pattern=inputFile,full.names = TRUE,recursive=TRUE)
Size = length(listFile)

rs = data.frame()
for(i in 1:Size){
	filename = listFile[i]
	start_index = regexpr("_[1-9]",filename)+1
	end_index = regexpr("km.csv",filename)
	rt = substr(filename,start_index,end_index)
	data = read.csv(filename)
	sample = nrow(data)
	correl = cor(data[,5],data[,6])
	correl = round(correl,3)
	rs = rbind(rs,data.frame(rt,sample,correl))
}
outputFile = paste("C:/out2/",inputFile,".csv",sep="")
write.csv(rs,outputFile)
print("done")


samples = nrow(data)
attach(data)

model_r1 = cor(pm1,sat_aod)
r1= round(model_r1*model_r1,3)

model_r2 = cor(pm25,sat_aod)
r2= round(model_r2*model_r2,3)

model_r3 = cor(pm10,sat_aod)
r3= round(model_r3*model_r3,3)

## model_r4 = cor(cem_temp,sat_temp)
## r4= round(model_r4*model_r4,3)


samples
r1
r2
r3
## r4

